<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue中多个元素或组件的过渡</title>
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
    <!-- <script src="../../velocity.js"></script> -->
    <style>
        .v-enter, .v-leave-to {
            opacity: 0;
        }
        .v-enter-active, .v-leave-active {
            transition: opacity 1s;
        }
    </style>
</head>
<body>
    <div id='app'>
        <transition mode="out-in">
            <component :is="type"></component>
            <!-- <child v-if="show" key="hello"></child>
            <child-one v-else key="bye"></child-one> -->
            <!-- <div v-if="show" key="hello">Hello World</div>
            <div v-else key="bye">Bye World</div> -->
        </transition>
        <button @click="handleClick">toggle</button>
    </div>

    <script>
        Vue.component('child', {
            template: '<div>child</div>'
        })

        Vue.component('child-one', {
            template: '<div>child-one</div>'
        })

        var vm = new Vue({
            el: '#app',
            data: {
                type: 'child'
            },
            methods: {
                handleClick: function() {
                    this.type = this.type === 'child' ? 'child-one' : 'child'
                }
            }
        })
    </script>
</body>
</html>